package cn.iocoder.yudao.module.dine.category.service.admin;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.service.CrudService;
import cn.iocoder.yudao.framework.business.basic.service.impl.BaseService;
import cn.iocoder.yudao.module.dine.category.convert.DineCategoryConvert;
import cn.iocoder.yudao.module.dine.category.dao.DineCategoryMapper;
import cn.iocoder.yudao.module.dine.category.pojo.dto.DineCategoryQueryDTO;
import cn.iocoder.yudao.module.dine.category.pojo.dto.DineCategorySaveDTO;
import cn.iocoder.yudao.module.dine.category.pojo.po.DineCategory;
import cn.iocoder.yudao.module.dine.category.pojo.vo.DineCategoryVO;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserLastShopId;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * 服务
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/07/18
 */
@Service
public class DineCategoryService extends BaseService<DineCategory, DineCategoryVO, DineCategoryQueryDTO> implements CrudService<DineCategory, DineCategoryVO, DineCategorySaveDTO, DineCategoryQueryDTO> {
    @Resource
    private DineCategoryMapper dineCategoryMapper;

    @Override
    public DineCategoryMapper getInjectedMapper() {
        return dineCategoryMapper;
    }


    @Nonnull
    @Override
    protected CoreQueryWrapper<DineCategory> buildQueryWrapper(DineCategoryQueryDTO param) {
        CoreQueryWrapper<DineCategory> wrapper = super.buildQueryWrapper(param);
        wrapper.likeIfPresent("name", param.getKeyword());
        wrapper.eqIfPresent("enabled", param.getEnabled());
        wrapper.orderByAsc("sort");
        return wrapper;
    }

    @Override
    public DineCategoryVO convertToViewObject(DineCategory entity) {
        return DineCategoryConvert.INSTANCE.toViewObject(entity);
    }

    @Override
    public DineCategory convertToEntity(DineCategorySaveDTO param) {
        return DineCategoryConvert.INSTANCE.toEntity(param);
    }

    @Override
    public void beforeCreate(DineCategory entity, @Nullable Long userId) {
        entity.setShopId(getLoginUserLastShopId());
    }

}
